home *** CD-ROM | disk | FTP | other *** search
/ CU Amiga Super CD-ROM 13 / CU Amiga Magazine's Super CD-ROM 13 (1997)(EMAP Images)(GB)(Track 1 of 2)[!][issue 1997-08].iso / CUCD / Graphics / irit70 / src / irit / irit.c < prev    next >
C/C++ Source or Header  |  1997-04-09  |  36KB  |  884 lines

  1. /*****************************************************************************
  2. *   Main module of "Irit" - the 3d (not only polygonal) solid modeller.      *
  3. ******************************************************************************
  4. * (C) Gershon Elber, Technion, Israel Institute of Technology                *
  5. ******************************************************************************
  6. * Usage:                                     *
  7. *   Irit [-t] [-z]                                 *
  8. *                                         *
  9. * Written by:  Gershon Elber                Ver 3.0, Apr. 1990   *
  10. *****************************************************************************/
  11.  
  12. #include <stdio.h>
  13. #include <signal.h>
  14. #include <string.h>
  15. #include "program.h"
  16. #include "config.h"
  17. #include "ctrl-brk.h"
  18. #include "dosintr.h"
  19. #include "inptprsg.h"
  20. #include "iritprsr.h"
  21. #include "irit_soc.h"
  22. #include "objects.h"
  23. #include "primitiv.h"
  24. #include "iritgrap.h"
  25. #include "bool_lib.h"
  26. #include "trim_lib.h"
  27. #include "triv_lib.h"
  28. #include "symb_lib.h"
  29. #ifdef __WINNT__
  30. #include <direct.h>
  31. #endif /* __WINNT__ */
  32. #ifdef DJGCC
  33. #include "intr_lib.h"
  34. #include "intr_gr.h"
  35. #endif /* DJGCC */
  36.  
  37. #ifdef NO_CONCAT_STR
  38. static char
  39.     *VersionStr = "Irit        Version 7.0, Gershon Elber,\n\
  40.     (C) Copyright 1989/90-97 Gershon Elber, Non commercial use only.";
  41. #else
  42. static char
  43.     *VersionStr = "Irit            " IRIT_VERSION
  44.     ",    Gershon Elber,    " __DATE__ ",   " __TIME__ "\n"
  45.     IRIT_COPYRIGHT ", Non commercial use only.";
  46. #endif /* NO_CONCAT_STR */
  47.  
  48. static char
  49.      *CtrlStr = "Irit [-t] [-z] [file.irt]";
  50.  
  51. char *GlblHelpFileName = "irit.hlp";
  52.  
  53. static char
  54.     *GlblPrgmHeader = "                Irit - the not only polygonal solid modeller";
  55. static char
  56.     *GlblCopyRight  =
  57. #ifdef DJGCC
  58.      IRIT_COPYRIGHT ",  DJGCC " IRIT_VERSION ",   " __DATE__;
  59. #else
  60. #ifdef OS2GCC
  61.      IRIT_COPYRIGHT ",  OS2   " IRIT_VERSION ",   " __DATE__;
  62. #else
  63. #ifdef AMIGA
  64.      IRIT_COPYRIGHT ", Amiga  " IRIT_VERSION ",   " __DATE__;
  65. #else
  66. #ifdef __WINNT__
  67.      IRIT_COPYRIGHT ", Win NT/95 " IRIT_VERSION ",   " __DATE__;
  68. #else
  69. #ifdef NO_CONCAT_STR
  70.      "(C) Copyright 1989/90-97 Gershon Elber,  Unix  Version 7.0";
  71. #else
  72.      IRIT_COPYRIGHT ",  Unix  " IRIT_VERSION;
  73. #endif /* NO_CONCAT_STR */
  74. #endif /* __WINNT__ */
  75. #endif /* AMIGA */
  76. #endif /* OS2GCC */
  77. #endif /* DJGCC */
  78. static char
  79.     *GlblAuthorName = "                         Written by Gershon Elber";
  80.  
  81. static int
  82.     GlblIritMallocDebugPrint = FALSE;
  83.  
  84. IPObjectStruct
  85.     *GlblObjList = NULL;           /* All objects defined on system. */
  86.  
  87. char GlblCrntWorkingDir[LINE_LEN];     /* Save start CWD to recover on exit. */
  88.  
  89. FILE
  90.     *GlblLogFile = NULL;
  91.  
  92. jmp_buf GlblLongJumpBuffer;                  /* Used in error recovery. */
  93.  
  94. int
  95. #ifdef DJGCC                       /* Defaults for intr_lib. */
  96.     GlblWindowFrameWidth = 8,
  97.     GlblViewFrameColor   = INTR_COLOR_RED,
  98.     GlblViewBackColor    = INTR_COLOR_BLACK,
  99.     GlblTransFrameColor  = INTR_COLOR_GREEN,
  100.     GlblTransBackColor   = INTR_COLOR_BLACK,
  101.     GlblStatusFrameColor = INTR_COLOR_MAGENTA,
  102.     GlblStatusBackColor  = INTR_COLOR_BLACK,
  103.     GlblInputFrameColor  = INTR_COLOR_YELLOW,
  104.     GlblInputBackColor   = INTR_COLOR_BLACK,
  105.     GlblDrawHeader       = FALSE,
  106.     GlblSmoothTextScroll = TRUE,
  107.     GlblIntrSaveMethod   = INTR_SAVE_DISK,
  108.     GlblMouseSensitivity = 10,       /* Sensitivity control of mouse device. */
  109.     GlblJoystickExists   = FALSE,
  110. #endif /* DJGCC */
  111.     GlblDisplayDeviceInput = -1,
  112.     GlblDisplayDeviceOutput = -1,
  113.     GlblInterpProd     = TRUE,
  114.     GlblLoadColor        = DEFAULT_LOAD_COLOR,
  115.     GlblPrimColor        = DEFAULT_PRIM_COLOR,
  116.     GlblDoGraphics       = TRUE,/* Control if running in graphics/text mode. */
  117.     GlblFatalError       = FALSE, /* True if disaster in system - must quit! */
  118.     GlblPrintLogFile     = FALSE,    /* If TRUE everything goes to log file. */
  119.     GlblPointLenAux      = IG_POINT_DEFAULT_LENGTH;
  120.  
  121. RealType
  122.     GlblPointLen = 0.02;               /* Scaler for point if drawn. */
  123.  
  124. char
  125. #ifdef DJGCC                       /* Defaults for intr_lib. */
  126.     *GlblViewWndwPos   = "0.02, 0.02, 0.72, 0.66",
  127.     *GlblTransWndwPos  = "0.75, 0.02, 0.98, 0.66",
  128.     *GlblStatusWndwPos = "0.75, 0.02, 0.98, 0.66",
  129.     *GlblInputWndwPos  = "0.04, 0.7,  0.98, 0.98",
  130.     *GlblIntrSaveDisk  = "c:\\",
  131. #endif /* DJGCC */
  132.     *GlblStartFileName = "",
  133.     *GlblLogFileName = "",
  134. #ifdef IRIT_DOUBLE
  135.     *GlblFloatFormat = "%-8.6lg";
  136. #else
  137.     *GlblFloatFormat = "%-8.6g";
  138. #endif /* IRIT_DOUBLE */
  139.  
  140. static ConfigStruct SetUp[] =
  141. {
  142. #ifdef DJGCC
  143.   { "Joystick",        "",   (VoidPtr) &GlblJoystickExists, SU_BOOLEAN_TYPE },
  144.   { "MouseSensitivity",    "",   (VoidPtr) &GlblMouseSensitivity,SU_INTEGER_TYPE },
  145.   { "WndwWidth",    "",   (VoidPtr) &GlblWindowFrameWidth,SU_INTEGER_TYPE },
  146.   { "WndwHeader",    "",   (VoidPtr) &GlblDrawHeader,     SU_BOOLEAN_TYPE },
  147.   { "WndwSmthTxtScrl",    "",   (VoidPtr) &GlblSmoothTextScroll,SU_BOOLEAN_TYPE },
  148.   { "WndwViewClr",    "",   (VoidPtr) &GlblViewFrameColor, SU_INTEGER_TYPE },
  149.   { "WndwTransClr",    "",   (VoidPtr) &GlblTransFrameColor,SU_INTEGER_TYPE },
  150.   { "WndwInputClr",    "",   (VoidPtr) &GlblInputFrameColor,SU_INTEGER_TYPE },
  151.   { "WndwViewPos",    "",   (VoidPtr) &GlblViewWndwPos,    SU_STRING_TYPE },
  152.   { "WndwTransPos",    "",   (VoidPtr) &GlblStatusWndwPos,  SU_STRING_TYPE },
  153.   { "WndwInputPos",    "",   (VoidPtr) &GlblInputWndwPos,   SU_STRING_TYPE },
  154.   { "WndwBackSave",    "",   (VoidPtr) &GlblIntrSaveMethod, SU_INTEGER_TYPE },
  155.   { "WndwBackSavePath",    "",   (VoidPtr) &GlblIntrSaveDisk,   SU_STRING_TYPE },
  156. #endif /* DJGCC */
  157.   { "DoGraphics",    "-t", (VoidPtr) &GlblDoGraphics,     SU_BOOLEAN_TYPE },
  158.   { "InterpProd",    "",   (VoidPtr) &GlblInterpProd,     SU_BOOLEAN_TYPE },
  159.   { "PointLength",    "",   (VoidPtr) &GlblPointLenAux,    SU_INTEGER_TYPE },
  160.   { "LoadColor",    "",   (VoidPtr) &GlblLoadColor,         SU_INTEGER_TYPE },
  161.   { "PrimColor",    "",   (VoidPtr) &GlblPrimColor,         SU_INTEGER_TYPE },
  162.   { "StartFile",    "",   (VoidPtr) &GlblStartFileName,  SU_STRING_TYPE },
  163.   { "LogFile",        "",   (VoidPtr) &GlblLogFileName,    SU_STRING_TYPE },
  164.   { "FloatFrmt",    "",   (VoidPtr) &GlblFloatFormat,    SU_STRING_TYPE },
  165. };
  166. #define NUM_SET_UP    (sizeof(SetUp) / sizeof(ConfigStruct))
  167.  
  168. static void Interact(void);
  169. static void ValidateVariables(void);
  170. static void PrintInptPrsrError(void);
  171.  
  172. /*****************************************************************************
  173. * DESCRIPTION:                                                               M
  174. * Main module of IRIT - Read command line and do what is needed...         M
  175. *                                                                            *
  176. * PARAMETERS:                                                                M
  177. *   argc, argv:  Command line.                                               M
  178. *                                                                            *
  179. * RETURN VALUE:                                                              M
  180. *   void                                                                     M
  181. *                                                                            *
  182. * KEYWORDS:                                                                  M
  183. *   main                                                                     M
  184. *****************************************************************************/
  185. void main(int argc, char **argv)
  186. {
  187.     char *FullPathStartFileName;
  188.  
  189.     IritCPUTime(TRUE);                     /* Reset the clock. */
  190.  
  191.     Config("irit", SetUp, NUM_SET_UP);       /* Read config. file if exists. */
  192.  
  193.     while (argc >= 2) {
  194.         if (strncmp(argv[1], "-z", 2) == 0) {
  195.         fprintf(stderr, "\n%s\n\nUsage: %s\n", VersionStr, CtrlStr);
  196.         ConfigPrint(SetUp, NUM_SET_UP);
  197.         exit(0);
  198.         }
  199.     else if (strncmp(argv[1], "-t", 2) == 0) {
  200.         GlblDoGraphics = FALSE;
  201.     }
  202.     else {
  203.         break;
  204.     }
  205.         argv++;
  206.     argc--;
  207.     }
  208.  
  209.     getcwd(GlblCrntWorkingDir, LINE_LEN - 1);
  210.  
  211.     SetUpCtrlBrk();         /* Set up control break trap routine (int 1bh). */
  212.     signal(SIGFPE, DefaultFPEHandler);     /* Will trap floating point errors. */
  213.  
  214.     BspMultInterpFlag(GlblInterpProd);
  215.     IritPrsrSetFloatFormat(GlblFloatFormat);
  216.     IritPrsrSetFlattenObjects(FALSE);
  217.     IritPrsrSetPolyListCirc(TRUE);
  218.  
  219.     /* Print some copyright messages: */
  220.     WndwInputWindowPutStr(GlblPrgmHeader);
  221.     WndwInputWindowPutStr(GlblCopyRight);
  222.     WndwInputWindowPutStr(GlblAuthorName);
  223.  
  224.     SetUpPredefObjects();          /* Prepare the predefined objects. */
  225.  
  226.     /* Execute the file specified in the command line if was one: */
  227.     if (argc == 2)
  228.     FileInclude(argv[1]);
  229.  
  230.     /* Execute the start up file first by inserting it to the include stack. */
  231.     if ((int) strlen(GlblStartFileName) > 0 &&
  232.     (FullPathStartFileName = searchpath(GlblStartFileName)) != NULL)
  233.     FileInclude(FullPathStartFileName);
  234.  
  235.     Interact();                      /* Go and do some real work... */
  236.  
  237.     IritExit(0);
  238. }
  239.  
  240. /*****************************************************************************
  241. * DESCRIPTION:                                                               *
  242. * Interact - the main read/eval/print routine. This routine reads data from  *
  243. * standart input and execute it "forever" (using Input Parser).             *
  244. *   Note exit from this program is controled by input parser itself.         *
  245. *                                                                            *
  246. * PARAMETERS:                                                                *
  247. *   None                                                                     *
  248. *                                                                            *
  249. * RETURN VALUE:                                                              *
  250. *   void                                                                     *
  251. *****************************************************************************/
  252. static void Interact(void)
  253. {
  254.     /* setjmp return 0 on first install time. Will return 1 if error is      */
  255.     /* recoverable, 2 if cannt continue - must quit the program now.         */
  256.     switch (setjmp(GlblLongJumpBuffer)) {         /* Used in error recovery. */
  257.     case 1:
  258.         ValidateVariables();
  259.     case 0:
  260.         while (TRUE) {
  261.         if (!InputParser())         /* Print the error message. */
  262.             PrintInptPrsrError();
  263.         ValidateVariables();
  264.         if (GlblIritMallocDebugPrint) {
  265.             GlblIritMallocDebugPrint = FALSE;
  266.             IritDebugMallocAllocated();
  267.         }
  268.         }
  269.     case 2:
  270.         WndwInputWindowPutStr("Press return to die...");
  271.         getchar();
  272.         break;
  273.     }
  274. }
  275.  
  276. /*****************************************************************************
  277. * DESCRIPTION:                                                               *
  278. *   Validates all the variables in the global list, scream and remove        *
  279. * undefined variables.                                                       *
  280. *                                                                            *
  281. * PARAMETERS:                                                                *
  282. *   None                                                                     *
  283. *                                                                            *
  284. * RETURN VALUE:                                                              *
  285. *   void                                                                     *
  286. *****************************************************************************/
  287. static void ValidateVariables(void)
  288. {
  289.     IPObjectStruct *PObj, *PTmp;
  290.     char Line[LINE_LEN];
  291.  
  292.     while (GlblObjList != NULL && IP_IS_UNDEF_OBJ(GlblObjList)) {
  293.     sprintf(Line,
  294.         "Error: undefined object \"%s\" has been removed from global data base\n",
  295.         GlblObjList -> Name);
  296.     WndwInputWindowPutStr(Line);
  297.  
  298.     PObj = GlblObjList -> Pnext;
  299.     IPFreeObject(GlblObjList);
  300.     GlblObjList = PObj;
  301.     }
  302.  
  303.     if (GlblObjList) {
  304.     for (PObj = GlblObjList; PObj -> Pnext != NULL; PObj = PObj -> Pnext) {
  305.         if (IP_IS_UNDEF_OBJ(PObj -> Pnext)) {
  306.         sprintf(Line,
  307.             "Error: undefined object \"%s\" has been removed from global data base\n",
  308.             PObj -> Pnext -> Name);
  309.         WndwInputWindowPutStr(Line);
  310.  
  311.         PTmp = PObj -> Pnext -> Pnext;
  312.         IPFreeObject(PObj -> Pnext);
  313.         PObj -> Pnext = PTmp;
  314.         }
  315.     }
  316.     }
  317. }
  318.  
  319. /*****************************************************************************
  320. * DESCRIPTION:                                                               M
  321. * Modifies the state of the IRIT solid modeller.                 M
  322. *                                                                            *
  323. * PARAMETERS:                                                                M
  324. *   Name:      Name of state variable.                                       M
  325. *   Data:      New value of state variable.                                  M
  326. *                                                                            *
  327. * RETURN VALUE:                                                              M
  328. *   void                                                                     M
  329. *                                                                            *
  330. * KEYWORDS:                                                                  M
  331. *   SetIritState                                                             M
  332. *****************************************************************************/
  333. void SetIritState(char *Name, IPObjectStruct *Data)
  334. {
  335.     if (stricmp(Name, "Coplanar") == 0) {
  336.     if (IP_IS_NUM_OBJ(Data))
  337.         BoolSetHandleCoplanarPoly(REAL_TO_INT(Data -> U.R));
  338.     else
  339.         WndwInputWindowPutStr("Numeric state value expected");
  340.     }
  341.     else if (stricmp(Name, "DebugFunc") == 0) {
  342.     if (IP_IS_NUM_OBJ(Data))
  343.         InptPrsrDebugFuncLevel(REAL_TO_INT(Data -> U.R));
  344.     else
  345.         WndwInputWindowPutStr("Numeric state value expected");
  346.     }
  347.     else if (stricmp(Name, "DebugMalloc") == 0) {
  348.     if (IP_IS_STR_OBJ(Data)) {
  349.         if (stricmp(Data -> U.Str, "Reset") == 0)
  350.         IritDebugMallocReset();
  351.         else if (strcmp(Data -> U.Str, "Print") == 0) {
  352.         /* Delay print until parsing tree of this command is free. */
  353.         GlblIritMallocDebugPrint = TRUE;
  354.         }
  355.         else {
  356.         int i;
  357.         long l;
  358.  
  359.         if (sscanf(Data -> U.Str, "%lx,%d", &l, &i) == 2 ||
  360.             sscanf(Data -> U.Str, "%ld,%d", &l, &i) == 2) {
  361.             char Line[LINE_LEN];
  362.  
  363.             sprintf(Line,
  364.                 "Malloc searching for %ld (0x%08lx), abort = %d",
  365.                 l, (unsigned long) l, i);
  366.             WndwInputWindowPutStr(Line);
  367.             IritDebugMallocSearchPtr((VoidPtr) l, i);
  368.         }
  369.         }
  370.     }
  371.     else
  372.         WndwInputWindowPutStr("String state value expected");
  373.     }
  374.     else if (stricmp(Name, "DumpLevel") == 0) {
  375.     if (IP_IS_NUM_OBJ(Data))
  376.         SetDumpLevel(REAL_TO_INT(Data -> U.R));
  377.     else
  378.         WndwInputWindowPutStr("Numeric state value expected");
  379.     }
  380.     else if (stricmp(Name, "EchoSource") == 0) {
  381.     if (IP_IS_NUM_OBJ(Data))
  382.         InptPrsrEchoSource(REAL_TO_INT(Data -> U.R));
  383.     else
  384.         WndwInputWindowPutStr("Numeric state value expected");
  385.     }
  386.     else if (stricmp(Name, "FloatFrmt") == 0) {
  387.     if (IP_IS_STR_OBJ(Data)) {
  388.         strcpy(GlblFloatFormat, Data -> U.Str);
  389.         IritPrsrSetFloatFormat(GlblFloatFormat);
  390.     }
  391.     else
  392.         WndwInputWindowPutStr("String state value expected");
  393.     }
  394.     else if (stricmp(Name, "InterCrv") == 0) {
  395.     if (IP_IS_NUM_OBJ(Data))
  396.         BoolSetOutputInterCurve(REAL_TO_INT(Data -> U.R));
  397.     else
  398.         WndwInputWindowPutStr("Numeric state value expected");
  399.     }
  400.     else if (stricmp(Name, "InterpProd") == 0) {
  401.     if (IP_IS_NUM_OBJ(Data))
  402.         BspMultInterpFlag(REAL_TO_INT(Data -> U.R));
  403.     else
  404.         WndwInputWindowPutStr("Numeric state value expected");
  405.     }
  406.     else if (stricmp(Name, "PolySort") == 0) {
  407.     if (IP_IS_NUM_OBJ(Data))
  408.         BoolSetPolySortAxis(REAL_TO_INT(Data -> U.R));
  409.     else
  410.         WndwInputWindowPutStr("Numeric state value expected");
  411.     }
  412.     else if (stricmp(Name, "PrimSrfs") == 0) {
  413.     if (IP_IS_NUM_OBJ(Data)) {
  414.         PrimSetPolygonalPrimitives(!REAL_TO_INT(Data -> U.R));
  415.     }
  416.     else
  417.         WndwInputWindowPutStr("Numeric state value expected");
  418.     }
  419.     else if (stricmp(Name, "PrimRatSrfs") == 0) {
  420.     if (IP_IS_NUM_OBJ(Data)) {
  421.         PrimSetSurfacePrimitiveRational(REAL_TO_INT(Data -> U.R));
  422.     }
  423.     else
  424.         WndwInputWindowPutStr("Numeric state value expected");
  425.     }
  426.     else if (stricmp(Name, "TrimCrvs") == 0) {
  427.     if (IP_IS_NUM_OBJ(Data)) {
  428.         TrimSetEuclidComposedFromUV(Data -> U.R <= 0);
  429.         TrimSetTrimCrvLinearApprox((int) (fabs(Data -> U.R)),
  430.                        SYMB_CRV_APPROX_UNIFORM);
  431.     }
  432.     else
  433.         WndwInputWindowPutStr("Numeric state value expected");
  434.     }
  435.     else if (stricmp(Name, "UVBoolean") == 0) {
  436.     if (IP_IS_NUM_OBJ(Data))
  437.         BoolSetParamSurfaceUVVals(REAL_TO_INT(Data -> U.R));
  438.     else
  439.         WndwInputWindowPutStr("Numeric state value expected");
  440.     }
  441. }
  442.  
  443. /*****************************************************************************
  444. * DESCRIPTION:                                                               *
  445. * Routine to query (and print) the errors found by InputParser.             *
  446. *                                                                            *
  447. * PARAMETERS:                                                                *
  448. *   None                                                                     *
  449. *                                                                            *
  450. * RETURN VALUE:                                                              *
  451. *   void                                                                     *
  452. *****************************************************************************/
  453. static void PrintInptPrsrError(void)
  454. {
  455.     InptPrsrEvalErrType ErrorNum;
  456.     char *ErrorMsg, *p;
  457.     char Line[LINE_LEN_LONG];
  458.  
  459.     if ((ErrorNum = InptPrsrParseError(&ErrorMsg)) != IPE_NO_ERR) {/*Prsr err*/
  460.     sprintf(Line, "Parsing Error: ");
  461.     p = &Line[strlen(Line)];
  462.     switch (ErrorNum) {
  463.         case IP_ERR_WRONG_SYNTAX:
  464.         sprintf(p, "Wrong syntax\n");
  465.         break;
  466.         case IP_ERR_PARAM_EXPECT:
  467.         sprintf(p, "Parameter Expected\n");
  468.         break;
  469.         case IP_ERR_ONE_OPERAND:
  470.         case IP_ERR_TWO_OPERAND:
  471.         sprintf(p, "Wrong # of operands - %s\n", ErrorMsg);
  472.         break;
  473.         case IP_ERR_STACK_OV:
  474.         sprintf(p, "Internal Stack OverFlow at - %s\n", ErrorMsg);
  475.         break;
  476.         case IP_ERR_PARAM_MATCH:
  477.         sprintf(p, "Parenthesis mismatch - %s\n", ErrorMsg);
  478.         break;
  479.         case IP_ERR_UNDEF_TOKEN:
  480.         sprintf(p, "Undefined token - %s\n", ErrorMsg);
  481.         break;
  482.         case IP_ERR_UNDEF_FUNC:
  483.         sprintf(p, "Undefined function - %s\n", ErrorMsg);
  484.         break;
  485.         case IP_ERR_NAME_TOO_LONG:
  486.         sprintf(p, "Object name too long - %s\n", ErrorMsg);
  487.         break;
  488.         case IP_ERR_PARAM_FUNC:
  489.         sprintf(p, "Parameters expected in func %s\n", ErrorMsg);
  490.         break;
  491.         case IP_ERR_NO_PARAM_FUNC:
  492.         sprintf(p, "No Parameters expected in func %s\n", ErrorMsg);
  493.         break;
  494.         case IP_ERR_STR_TOO_LONG:
  495.         sprintf(p, "String too long - %s\n", ErrorMsg);
  496.         break;
  497.         default:
  498.         sprintf(p, "Undefined error %d", ErrorNum);
  499.         break;
  500.     }
  501.     WndwInputWindowPutStr(Line);
  502.     return;
  503.     }
  504.  
  505.     if ((ErrorNum = InptPrsrEvalError(&ErrorMsg)) != IPE_NO_ERR) {/*Eval err.*/
  506.     sprintf(Line, "Eval Error: ");
  507.     p = &Line[strlen(Line)];
  508.     switch (ErrorNum) {
  509.         case IE_ERR_FATAL_ERROR:
  510.         sprintf(p, "Fatal error - %s\n", ErrorMsg);
  511.         break;
  512.         case IE_ERR_DIV_BY_ZERO:
  513.         sprintf(p, "Division by zero - %s\n", ErrorMsg);
  514.         break;
  515.         case IE_ERR_NO_OBJ_METHOD:
  516.         sprintf(p, "No such method for object - %s\n", ErrorMsg);
  517.         break;
  518.         case IE_ERR_TYPE_MISMATCH:
  519.         sprintf(p, "Parameter type mismatch - %s\n",
  520.             ErrorMsg);
  521.         break;
  522.         case IE_ERR_ASSIGN_LEFT_OP:
  523.         sprintf(p, "Lval is not a parameter - %s\n", ErrorMsg);
  524.         break;
  525.         case IE_ERR_MIXED_OBJ:
  526.         sprintf(p, "Mixed types in expression - %s\n", ErrorMsg);
  527.         break;
  528.         case IE_ERR_IP_OBJ_UNDEFINED:
  529.         sprintf(p, "No such object defined - %s\n", ErrorMsg);
  530.         break;
  531.         case IE_ERR_NO_ASSIGNMENT:
  532.         sprintf(p, "Assignment was expected\n");
  533.         break;
  534.         case IE_ERR_FP_ERROR:
  535.         sprintf(p, "Floating Point Error - %s\n", ErrorMsg);
  536.         break;
  537.         case IE_ERR_NUM_PRM_MISMATCH:
  538.         sprintf(p, "Number of func. param. mismatch - %s\n", ErrorMsg);
  539.         break;
  540.         case IE_ERR_MAT_POWER:
  541.         sprintf(p, "Wrong range or not exists, operator - %s\n", ErrorMsg);
  542.         break;
  543.         case IE_ERR_FREE_SIMPLE:
  544.         sprintf(p, "Free only geometric objects - %s\n", ErrorMsg);
  545.         break;
  546.         case IE_ERR_MODIF_ITER_VAR:
  547.         sprintf(p, "Iteration var. type modified or freed - %s\n", ErrorMsg);
  548.         break;
  549.         case IE_ERR_BOOLEAN_ERR:
  550.         sprintf(p, "Geometric Boolean operation error - %s\n", ErrorMsg);
  551.         break;
  552.         case IE_ERR_OUT_OF_RANGE:
  553.         sprintf(p, "Out of range.\n");
  554.         break;
  555.         case IE_ERR_DATA_PRSR_ERROR:
  556.         sprintf(p, "%s", ErrorMsg);
  557.         break;
  558.         case IE_ERR_USER_FUNC_NO_RETVAL:
  559.         sprintf(p, "User defined function \"%s\" has no returned value\n",
  560.             ErrorMsg);
  561.         break;
  562.         case IE_ERR_INCOMPARABLE_TYPES:
  563.         sprintf(p, "Incomparable object types found");
  564.         break;
  565.         case IE_ERR_ONLYEQUALITY_TEST:
  566.         sprintf(p, "Only equality or non equality test is valid for these objects");
  567.         break;
  568.         case IE_ERR_IF_HAS_NO_COND:
  569.         sprintf(p, "Condition of if clause is illegal");
  570.         break;
  571.         case IE_ERR_IP_USERFUNC_DUP_VAR:
  572.         sprintf(p, "Duplicated variable, %s", ErrorMsg);
  573.         break;
  574.         case IE_ERR_UNDEF_INSTANCE:
  575.         sprintf(p, "Undefined object to instantiate from, %s",
  576.             ErrorMsg);
  577.         break;
  578.         default:
  579.         sprintf(p, "Undefined error %d\n", ErrorNum);
  580.         break;
  581.     }
  582.     WndwInputWindowPutStr(Line);
  583.     return;
  584.     }
  585. }
  586.  
  587. /*****************************************************************************
  588. * DESCRIPTION:                                                               M
  589. * IRIT Exit routine. Error code of zero.                     M
  590. *                                                                            *
  591. * PARAMETERS:                                                                M
  592. *   None                                                                     *
  593. *                                                                            *
  594. * RETURN VALUE:                                                              M
  595. *   void                                                                     M
  596. *                                                                            *
  597. * KEYWORDS:                                                                  M
  598. *   IritExit0                                                                M
  599. *****************************************************************************/
  600. void IritExit0(void)
  601. {
  602.     IritExit(0);
  603. }
  604.  
  605. /*****************************************************************************
  606. * DESCRIPTION:                                                               M
  607. * IRIT Exit routine.                                                M
  608. *                                                                            *
  609. * PARAMETERS:                                                                M
  610. *   ExitCode:   Exit code.                                                   *
  611. *                                                                            *
  612. * RETURN VALUE:                                                              M
  613. *   void                                                                     M
  614. *                                                                            *
  615. * KEYWORDS:                                                                  M
  616. *   IritExit                                                                 M
  617. *****************************************************************************/
  618. void IritExit(int ExitCode)
  619. {
  620.     if (GlblDoGraphics) {
  621.         WndwViewExit();
  622.     }
  623.  
  624.     ClientCloseAll(TRUE);
  625.  
  626.     chdir(GlblCrntWorkingDir);      /* Recover original directory before exit. */
  627.  
  628.     if (GlblPrintLogFile)
  629.     fclose(GlblLogFile);              /* Close log file if was open. */
  630.  
  631.     exit(ExitCode);
  632. }
  633.  
  634. /*****************************************************************************
  635. * DESCRIPTION:                                                               M
  636. * Traps Cagd_lib errors right here. Call back function of cagd_lib.         M
  637. *                                                                            *
  638. * PARAMETERS:                                                                M
  639. *   ErrID:    Error number in cagd_lib library.                              M
  640. *                                                                            *
  641. * RETURN VALUE:                                                              M
  642. *   void                                                                     M
  643. *                                                                            M
  644. * KEYWORDS:                                                                  M
  645. *   CagdFatalError                                                           M
  646. *****************************************************************************/
  647. void CagdFatalError(CagdFatalErrorType ErrID)
  648. {
  649.     char Line[LINE_LEN],
  650.     *ErrorMsg = CagdDescribeError(ErrID);
  651.  
  652.     sprintf(Line, "CAGD_LIB: %s", ErrorMsg);
  653.     WndwInputWindowPutStr(Line);
  654.  
  655.     FlushToEndOfExpr(TRUE);
  656.  
  657.     longjmp(GlblLongJumpBuffer, 1);       /* Go back to main loop directly. */
  658. }
  659.  
  660. /*****************************************************************************
  661. * DESCRIPTION:                                                               M
  662. * Traps Symb_lib errors right here. Call back function of symb_lib.         M
  663. *                                                                            *
  664. * PARAMETERS:                                                                M
  665. *   ErrID:    Error number in symb_lib library.                              M
  666. *                                                                            *
  667. * RETURN VALUE:                                                              M
  668. *   void                                                                     M
  669. *                                                                            M
  670. * KEYWORDS:                                                                  M
  671. *   SymbFatalError                                                           M
  672. *****************************************************************************/
  673. void SymbFatalError(SymbFatalErrorType ErrID)
  674. {
  675.     char Line[LINE_LEN],
  676.     *ErrorMsg = SymbDescribeError(ErrID);
  677.  
  678.     sprintf(Line, "SYMB_LIB: %s", ErrorMsg);
  679.     WndwInputWindowPutStr(Line);
  680.  
  681.     FlushToEndOfExpr(TRUE);
  682.  
  683.     longjmp(GlblLongJumpBuffer, 1);       /* Go back to main loop directly. */
  684. }
  685.  
  686. /*****************************************************************************
  687. * DESCRIPTION:                                                               M
  688. * Traps Trim_lib errors right here. Call back function of trim_lib.         M
  689. *                                                                            *
  690. * PARAMETERS:                                                                M
  691. *   ErrID:    Error number in trim_lib library.                              M
  692. *                                                                            *
  693. * RETURN VALUE:                                                              M
  694. *   void                                                                     M
  695. *                                                                            M
  696. * KEYWORDS:                                                                  M
  697. *   TrimFatalError                                                           M
  698. *****************************************************************************/
  699. void TrimFatalError(TrimFatalErrorType ErrID)
  700. {
  701.     char Line[LINE_LEN],
  702.     *ErrorMsg = TrimDescribeError(ErrID);
  703.  
  704.     sprintf(Line, "TRIM_LIB: %s", ErrorMsg);
  705.     WndwInputWindowPutStr(Line);
  706.  
  707.     FlushToEndOfExpr(TRUE);
  708.  
  709.     longjmp(GlblLongJumpBuffer, 1);       /* Go back to main loop directly. */
  710. }
  711.  
  712. /*****************************************************************************
  713. * DESCRIPTION:                                                               M
  714. * Traps Triv_lib errors right here. Call back function of triv_lib.         M
  715. *                                                                            *
  716. * PARAMETERS:                                                                M
  717. *   ErrID:    Error number in triv_lib library.                              M
  718. *                                                                            *
  719. * RETURN VALUE:                                                              M
  720. *   void                                                                     M
  721. *                                                                            M
  722. * KEYWORDS:                                                                  M
  723. *   TrivFatalError                                                           M
  724. *****************************************************************************/
  725. void TrivFatalError(TrivFatalErrorType ErrID)
  726. {
  727.     char Line[LINE_LEN],
  728.     *ErrorMsg = TrivDescribeError(ErrID);
  729.  
  730.     sprintf(Line, "TRIV_LIB: %s", ErrorMsg);
  731.     WndwInputWindowPutStr(Line);
  732.  
  733.     FlushToEndOfExpr(TRUE);
  734.  
  735.     longjmp(GlblLongJumpBuffer, 1);       /* Go back to main loop directly. */
  736. }
  737.  
  738. /*****************************************************************************
  739. * DESCRIPTION:                                                               M
  740. * Traps Trng_lib errors right here. Call back function of trng_lib.         M
  741. *                                                                            *
  742. * PARAMETERS:                                                                M
  743. *   ErrID:    Error number in trng_lib library.                              M
  744. *                                                                            *
  745. * RETURN VALUE:                                                              M
  746. *   void                                                                     M
  747. *                                                                            M
  748. * KEYWORDS:                                                                  M
  749. *   TrivFatalError                                                           M
  750. *****************************************************************************/
  751. void TrngFatalError(TrngFatalErrorType ErrID)
  752. {
  753.     char Line[LINE_LEN],
  754.     *ErrorMsg = TrngDescribeError(ErrID);
  755.  
  756.     sprintf(Line, "TRNG_LIB: %s", ErrorMsg);
  757.     WndwInputWindowPutStr(Line);
  758.  
  759.     FlushToEndOfExpr(TRUE);
  760.  
  761.     longjmp(GlblLongJumpBuffer, 1);       /* Go back to main loop directly. */
  762. }
  763.  
  764. /*****************************************************************************
  765. * DESCRIPTION:                                                               M
  766. * Prints IRIT none fatal error message and go back to cursor mode.         M
  767. *                                                                            *
  768. * PARAMETERS:                                                                M
  769. *   ErrorMsg:    Error message to print out.                     M
  770. *                                                                            *
  771. * RETURN VALUE:                                                              M
  772. *   void                                                                     M
  773. *                                                                            M
  774. * KEYWORDS:                                                                  M
  775. *   TrivNonFatalError                                                        M
  776. *****************************************************************************/
  777. void IritNonFatalError(char *ErrorMsg)
  778. {
  779.     if (ErrorMsg != NULL) {
  780.     WndwInputWindowPutStr(ErrorMsg);
  781.     }
  782.  
  783.     FlushToEndOfExpr(TRUE);
  784.  
  785.     longjmp(GlblLongJumpBuffer, 1);       /* Go back to main loop directly. */
  786. }
  787.  
  788. /*****************************************************************************
  789. * DESCRIPTION:                                                               M
  790. * Prints IRIT's fatal error message and go back to cursor mode.             M
  791. *                                                                            *
  792. * PARAMETERS:                                                                M
  793. *   ErrorMsg:    Error message to print out.                     M
  794. *                                                                            *
  795. * RETURN VALUE:                                                              M
  796. *   void                                                                     M
  797. *                                                                            M
  798. * KEYWORDS:                                                                  M
  799. *   IritPrsrFatalError                                                       M
  800. *****************************************************************************/
  801. void IritFatalError(char *ErrorMsg)
  802. {
  803.     if (ErrorMsg != NULL) {
  804.     WndwInputWindowPutStr("Fatal error occured, please report it:");
  805.     WndwInputWindowPutStr(ErrorMsg);
  806.     }
  807.  
  808.     FlushToEndOfExpr(TRUE);
  809.  
  810.     longjmp(GlblLongJumpBuffer, 1);       /* Go back to main loop directly. */
  811. }
  812.  
  813. /*****************************************************************************
  814. * DESCRIPTION:                                                               M
  815. * Prints IRIT parser's fatal error message and go back to cursor mode.         M
  816. *                                                                            *
  817. * PARAMETERS:                                                                M
  818. *   ErrorMsg:    Error message to print out.                     M
  819. *                                                                            *
  820. * RETURN VALUE:                                                              M
  821. *   void                                                                     M
  822. *                                                                            M
  823. * KEYWORDS:                                                                  M
  824. *   IritPrsrFatalError                                                       M
  825. *****************************************************************************/
  826. void IritPrsrFatalError(char *ErrorMsg)
  827. {
  828.     if (ErrorMsg != NULL) {
  829.     WndwInputWindowPutStr(ErrorMsg);
  830.     }
  831.  
  832.     FlushToEndOfExpr(TRUE);
  833.  
  834.     longjmp(GlblLongJumpBuffer, 1);       /* Go back to main loop directly. */
  835. }
  836.  
  837. /*****************************************************************************
  838. * DESCRIPTION:                                                               M
  839. * Called from the floating point package in case of fatal floating point     M
  840. * error.                                     M
  841. *   Prints error message and long jumps to main loop.                 M
  842. *   Default FPE handler - must be reset after redirected to other module.    M
  843. *                                                                            *
  844. * PARAMETERS:                                                                M
  845. *   Type:      Of floating point error.                                      M
  846. *                                                                            *
  847. * RETURN VALUE:                                                              M
  848. *   void                                                                     M
  849. *                                                                            *
  850. * KEYWORDS:                                                                  M
  851. *   DefaultFPEHandler                                                        M
  852. *****************************************************************************/
  853. void DefaultFPEHandler(int Type)
  854. {
  855.     char Line[LINE_LEN];
  856.  
  857.     sprintf(Line, "Floating point error %d.", Type);
  858.     WndwInputWindowPutStr(Line);
  859.  
  860.     FlushToEndOfExpr(TRUE);
  861.  
  862.     longjmp(GlblLongJumpBuffer, 1);
  863. }
  864.  
  865. #ifdef DEBUG
  866.  
  867. /*****************************************************************************
  868. * DESCRIPTION:                                                               *
  869. *    Dummy function to link at debugging time.                               *
  870. *                                                                            *
  871. * PARAMETERS:                                                                *
  872. *                                                                            *
  873. * RETURN VALUE:                                                              *
  874. *   void                                                                     *
  875. *                                                                            *
  876. * KEYWORDS:                                                                  *
  877. *****************************************************************************/
  878. void DummyLinkCagdDebug(void)
  879. {
  880.     IritPrsrDbg();
  881. }
  882.  
  883. #endif /* DEBUG */
  884.